﻿using SaiLing.Domain.Specification;
using SaiLing.Paging;
using SaiLing.Repository;
using SaiLing.SingleSignOn.Domain.Entities.DataTransferObject;
using SaiLing.SingleSignOn.Domain.Entities.System;
using SaiLing.SingleSignOn.Domain.Interfaces.System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace SaiLing.SingleSignOn.Repository.Providers.System
{
    public class PositionRepository : BaseRepository<Position>, IPositionRepository
    {
        public PositionRepository(IDatabaseFactory<ProjectDbContext> databaseFactory) : base(databaseFactory)
        {

        }

        public Task<PageData<PositionDTO>> PageDataList<TS>(int pageIndex, int pageSize, ISpecification<Position> specification, Expression<Func<PositionDTO, TS>> orderByExpression, bool isDesc)
        {
            var result = from x in DataContext.Set<Position>().Where(specification.SatisfiedBy())
                         select new PositionDTO
                         {
                             FullName = x.FullName,
                             Id = x.Id,
                             OrganizationId = x.OrganizationId,
                             OrganizationName = x.Organization.FullName,
                             ShortName = x.ShortName,
                             Sort = x.Sort,
                             IsManage = x.IsManage

                         };
            return result.ToPageData(pageIndex, pageSize);
        }
    }
}
